// const buf1 = Buffer.alloc(256);
// const buf2 = Buffer.from(new Array(255));
// const buf3 = Buffer.allocUnsafe(10);
// buf3.fill(0);
// const buf4 = Buffer.from(["0".repeat(256)]);
// var name1 = "chenzeyu";
// var name2 = "陈则瑜";
// var len = buf1.write(name1);
// // console.log("写入字节大小: "+len);
// len = buf1.write(name2,name1.length);
// // console.log("写入字节大小: "+len);
// // console.log("写入内容: "+buf1.toString());
// const buf5 = Buffer.from("好好学习");
// const buf6 = Buffer.concat([buf1,buf5]);
// console.log("写入内容: "+buf6.toString());

const fs = require("fs");
// fs.writeFile("./a332.txt","123456789123456789123456789",(err) => {
//     if (err != null) {
//         console.error(err);
//     } else {
//         console.log('文件写入成功');
//     }
// });

// var readerStream = fs.createReadStream('./a332.txt');
// readerStream.setEncoding('UTF8');
// var count = 0;
// readerStream.on('data', (chunk) => {
//     count++;
//     console.log("读取次数："+count+"，读取大小："+chunk.length+"，读取内容："+chunk);
// });

// readerStream.on('end', () => {
//     console.log('读取完成');
// });

// readerStream.on('error', (err) => {
//     console.error('读取错误：', err);
// });
const zlib = require('zlib');
const readStream = fs.createReadStream("./a332.txt");
const writeStream = fs.createWriteStream("./czy332.txt.gz");
const gzipStream = zlib.createGzip();

readStream.pipe(gzipStream).pipe(writeStream);

writeStream.on('finish', () => {
  console.log('复制完成');
});

writeStream.on('error', (err) => {
  console.error('复制错误：', err);
});